﻿package mortal.game.view.market.buyAndQiugou
{
    import Message.Game.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.market.*;
    import mortal.mvc.core.*;

    public class MktQiugouListItem extends GCellRenderer
    {
        private var _item:BaseItem;
        private var _itemBg:GBitmap;
        private var _txtItemName:GTextFiled;
        private var _txtLevel:GTextFiled;
        private var _bmpUintPrice:GBitmap;
        private var _txtUintPrice:GTextFiled;
        private var _bgUintPrice:ScaleBitmap;
        private var _btnBuy:GButton;
        private var _line:ScaleBitmap;
        private var _unit:int;

        public function MktQiugouListItem()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UIFactory.getUICompoment(BaseItem, 15, 5, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._txtItemName = UIFactory.gTextField("恶魔之刃", 57, 18, 100, 20, this);
            this._txtLevel = UIFactory.gTextField("50", 195, 18, 20, 20, this);
            this._bmpUintPrice = UIFactory.bitmap("", 265, 18, this);
            this._bgUintPrice = UIFactory.bg(290, 18, 60, 20, this, ImagesConst.InputDisablBg);
            this._txtUintPrice = UIFactory.gTextField("50", 290, 18, 60, 20, this);
            this._txtUintPrice.autoSize = TextFieldAutoSize.CENTER;
            this._btnBuy = UIFactory.gButton("出售", 415, 16, 45, 22, this);
            this._line = UIFactory.bg(0, 49, 474, 1, this, ImagesConst.SplitLine);
            this._btnBuy.configEventListener(MouseEvent.CLICK, this.clickHandler);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._txtItemName.dispose(param1);
            this._txtLevel.dispose(param1);
            this._bmpUintPrice.dispose(param1);
            this._bgUintPrice.dispose(param1);
            this._txtUintPrice.dispose(param1);
            this._btnBuy.dispose(param1);
            this._line.dispose(param1);
            this._item = null;
            this._txtItemName = null;
            this._txtLevel = null;
            this._bmpUintPrice = null;
            this._bgUintPrice = null;
            this._txtUintPrice = null;
            this._btnBuy = null;
            this._line = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:SMarketItem = null;
            var _loc_3:SPlayerItem = null;
            super.data = param1;
            if (param1 is SMarketItem)
            {
                _loc_2 = param1 as SMarketItem;
                if (_loc_2.code == EPriceUnit._EPriceUnitCoin || _loc_2.code == EPriceUnit._EPriceUnitGold)
                {
                    this._item.source = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitBigIcon(_loc_2.code));
                    this._txtItemName.htmlText = _loc_2.amount + GameDefConfig.instance.getEPrictUnitName(_loc_2.code);
                    this._txtLevel.text = "1";
                }
                else
                {
                    _loc_3 = new SPlayerItem();
                    _loc_3.itemCode = _loc_2.code;
                    _loc_3.jsStr = _loc_2.itemExtend;
                    _loc_3.itemAmount = _loc_2.amount;
                    this._item.itemData = new ItemData(_loc_3);
                    this._txtItemName.htmlText = ItemsUtil.getItemName(this._item.itemData);
                    this._txtLevel.text = this._item.itemData.itemInfo.level.toString();
                }
                this.unit = _loc_2.sellUnit;
                this._txtUintPrice.text = MktModConfig.getUnitPrice(_loc_2);
            }
            this._txtItemName.htmlText = "<a href=\'event:1\'>" + this._txtItemName.htmlText + "</a>";
            this._txtItemName.configEventListener(TextEvent.LINK, this.onNameLink);
            return;
        }// end function

        override public function get data() : Object
        {
            return super.data;
        }// end function

        private function onNameLink(event:TextEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSearchClickName, this.data));
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSellItem2SeekBuy, this.data));
            return;
        }// end function

        public function set unit(param1:int) : void
        {
            this._unit = param1;
            this._bmpUintPrice.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._bmpUintPrice.x = this._bgUintPrice.x - 22;
            this._bmpUintPrice.y = this._bgUintPrice.y + (this._bgUintPrice.height - this._bmpUintPrice.height) / 2;
            return;
        }// end function

    }
}
